package com.hzlj.position.config.common.enums;

import com.fz.common.base.exception.PubError;
import com.fz.common.base.exception.PubException;
import lombok.Getter;

/**
 * @author fanzhuo
 */

@Getter
public enum WarningType {
    SUCCESS("0", "成功"),
    FAIL("1", "失败"),
    CROSS("2", "越界"),
    POWER_OFF("3", "关机"),
    DEMOUNT("4", "拆卸"),
    LOWER_POWER("5", "低电"),
    VIRTUAL("6", "虚拟定位"),
    CROSS_LEAVING("7", "越界-外出请假"),
    NOT_OPEN("11", "未开通"),
    FAIL_CHECK("51", "失败(核实正常)"),
    CROSS_CHECK("52", "越界(核实正常)"),
    POWER_OFF_CHECK("53", "关机(核实正常)"),
    DEMOUNT_CHECK("54", "拆卸(核实正常)"),
    LOWER_POWER_CHECK("55", "低电(核实正常)"),
    VIRTUAL_CHECK("56", "低电(核实正常)"),
    CROSS_LEAVING_CHECK("57", "越界-外出请假(核实正常)"),
    ;

    private final String code;
    private final String text;

    WarningType(String code, String text) {
        this.code = code;
        this.text = text;
    }

    public static WarningType of(String warningType) {
        for (WarningType type : values()) {
            if (type.getCode().equals(warningType)) {
                return type;
            }
        }
        throw new PubException(PubError.PARAM_EMPTY_ERROR);
    }

    public boolean success() {
        return this.equals(SUCCESS);
    }

    public static boolean isCross(String warningType) {
        WarningType type = WarningType.of(warningType);
        return type.equals(CROSS)
                || type.equals(CROSS_LEAVING);
    }


    public static boolean isCrossWithHandle(String warningType) {
        WarningType type = WarningType.of(warningType);
        return isCross(warningType)
                || type.equals(CROSS_CHECK)
                || type.equals(CROSS_LEAVING_CHECK);
    }
}
